﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Weixin.BLL.ChinaTax;
using Weixin.Entity.ChinaTax;

namespace Weixin.Web
{
    public partial class Ask_txt : System.Web.UI.Page
    {
        int _AskId;
        public askEntity _AskEntity;
        public reAskEntity _ReAskEntity;

        #region jssdk
        protected string noncestr = string.Empty;
        protected string jsapi_ticket = string.Empty;
        protected string timestamp = string.Empty;
        protected string signature = string.Empty;

        protected string url = string.Empty;
        protected string title = string.Empty;
        protected string desc = string.Empty;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["askId"], out _AskId);

            GetData();
            GetJssdk();
        }

        void GetData()
        {
            askBLL _askBLL = askBLL.GetInstance();
            _AskEntity = _askBLL.GetAdminSingle(_AskId);
            if (_AskEntity == null || _AskEntity.flag == 0 || _AskEntity.isHot == 0)
            {
                _AskEntity = new askEntity();
            }

            reAskBLL _reAskBLL = reAskBLL.GetInstance();
            IList<reAskEntity> list = _reAskBLL.GetReAskListByAskId(_AskEntity.ID);
            foreach (reAskEntity entity in list)
            {
                if (entity.flag == 1 && entity.good == 1)
                {
                    _ReAskEntity = entity;
                    break;
                }
            }

            if (_ReAskEntity == null)
            {
                _ReAskEntity = new reAskEntity();
            }

            _AskEntity.hits = _AskEntity.hits + 1;
            _askBLL.Update(_AskEntity);
        }

        protected void GetJssdk()
        {
            WX wx = new WX();
            url = Request.Url.ToString().IndexOf("#") > -1 ? Request.Url.ToString().Substring(0, Request.Url.ToString().IndexOf("#")) : Request.Url.ToString();
            string[] arr = wx.GetJSSDK(url);
            noncestr = arr[0];
            jsapi_ticket = arr[1];
            timestamp = arr[2];
            signature = arr[3];

            title = _AskEntity.title;
            desc = _AskEntity.title;
        }
    }
}